package model

import (
	"blog_test/src/pkg/setting"
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

type Model struct {
	ID         int    `gorm:"primary_key" json:"id"`
	CreateBy   string `json:"created_by"`
	ModifiedBy string `json:"modified_by"`
	CreatedOn  int    `json:"created_on"`
	ModifiedOn int    `json:"modified_on"`
	DeletedOn  int    `json:"deleted_on"`
	IsDel      int    `json:"is_del"`
}

func NewDBEngine(databaseSetting *setting.DatabaseSettings) (*gorm.DB, error) {
	fmt.Println(databaseSetting)
	//s := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=%s&parseTime=%t&loc=Local")
	db, err := gorm.Open(databaseSetting.DBType, databaseSetting.UserName+":"+databaseSetting.Password+"@tcp("+databaseSetting.Host+")/"+databaseSetting.DBName+"?charset="+databaseSetting.Charset)
	if err != nil {
		return nil, err
	}
	return db, nil
}
